home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95b.txt / 000011_icon-group-sender _Thu Feb 9 10:46:19 1995.msg < prev    next >
Internet Message Format  |  1995-09-18  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 9 Feb 1995 09:46:28 MST
  2. From: cargo@ironwood.cray.com (David Cargo)
  3. Message-Id: <9502091646.AA02575@fir121>
  4. Date: Thu, 9 Feb 1995 10:46:19 -0600
  5. To: icon-group@cs.arizona.edu
  6. Subject: string invocation example
  7. X-Mailer: [XMailTool v3.1.0]
  8. Content-Length: 1658
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11.  
  12. The February Icon Analyst has a cover article about string invocation.
  13. I wrote this program to take advantage of string invocation for
  14. filtering text files in a flexible fashion.
  15.  
  16. ############################################################################
  17. #
  18. #    File:     filter.icn
  19. #
  20. #    Subject:  Program to apply Icon functions to lines of input
  21. #
  22. #    Author:   David S. Cargo
  23. #
  24. #    Date:     February 9, 1995
  25. #
  26. ############################################################################
  27. #
  28. #    Version:  1.1
  29. #
  30. ############################################################################
  31. #
  32. #   This program uses string invocation to apply an Icon function to lines
  33. #   of input to produce lines of output.  
  34. #  
  35. #
  36. ############################################################################
  37. #
  38. #  Links: none
  39. #
  40. #  Requires: string invocation
  41. #
  42. ############################################################################
  43.  
  44. procedure main(args)
  45.     local arglist, function_name, line
  46.     (*args > 0) | Usage()
  47.     function_name := get(args)
  48.     (function_name == function()) | possible_match(function_name)
  49.     if *args = 0
  50.     then while line := read() do write(function_name(line))
  51.     else
  52.         {
  53.     arglist := [] ||| args
  54.     while arglist[1] := read() do write(function_name!arglist)
  55.     }
  56.     return
  57. end
  58.  
  59. procedure Usage()
  60.     every write(function())
  61.     stop("Usage: filter functionname [arg1 [arg2 ...]] <stdin >stdout")
  62. end
  63.  
  64. procedure possible_match(function_name)
  65.     local fname
  66.     write(image(function_name), " is not the name of any function.")
  67.     every fname := function() do
  68.         if find(function_name, fname)
  69.         then write(fname)
  70.     stop()
  71. end